home *** CD-ROM | disk | FTP | other *** search
- #include <exec/libraries.h>
- #include <exec/memory.h>
- #include <graphics/text.h>
- #include <intuition/intuition.h>
- #include <intuition/screens.h>
- #include <intuition/GadgetClass.h>
- #include <libraries/gadtools.h>
- #include <utility/tagitem.h>
-
- #include <clib/exec_protos.h>
- #include <clib/gadtools_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/graphics_protos.h>
-
- #include "Cx.h"
- #include "Icon.h"
-
- #include "GUI.h"
-
- #define Speed_ID 1
- #define ClickToFront_ID 2
- #define MMBShift_ID 3
- #define Quit_ID 127
-
- struct TextAttr GUI_TopazFont = { "topaz.font", 8, 0, 0, };
-
- extern struct CxContext *Cx;
-
- struct Gadget *BuildQuitButton(struct GUIContext *gui,struct Gadget *glist)
- {
- struct NewGadget newgad;
- int topedge,leftedge,textwidth,textwidth2,id=Quit_ID;
-
- textwidth=TextLength(&gui->Screen->RastPort,"Quit",4);
- textwidth+=64;
-
- topedge=gui->BorderTop+gui->InnerHeight;
- leftedge=gui->BorderLeft+gui->InnerWidth/2-textwidth/2;
- gui->InnerHeight+=8+14;
-
- newgad.ng_TextAttr = &GUI_TopazFont;
- newgad.ng_VisualInfo = gui->VisualInfo;
- newgad.ng_LeftEdge = leftedge;
- newgad.ng_TopEdge = topedge;
- newgad.ng_Width = textwidth;
- newgad.ng_Height = 14;
- newgad.ng_GadgetText = "Quit";
- newgad.ng_GadgetID = id;
- newgad.ng_Flags = 0;
-
- glist = CreateGadget(BUTTON_KIND, glist, &newgad,
- GA_RelVerify,TRUE,
- TAG_DONE);
-
- return(glist);
- }
-
-
- struct Gadget *BuildCheckBoxes(struct GUIContext *gui,struct Gadget *glist)
- {
- struct NewGadget newgad;
- int topedge,leftedge,textwidth,textwidth2;
-
- BOOL ctf,mmb;
-
- if(Cx)
- {
- ctf=Cx->ClickToFront;
- mmb=Cx->MMBShift;
- }
- else
- {
- ctf=MatchToolType("ClickToFront","Yes");
- mmb=MatchToolType("MMBShift","Yes");
- }
-
- textwidth=TextLength(&gui->Screen->RastPort,"Click to Front",14);
- textwidth+=64;
-
- topedge=gui->BorderTop+gui->InnerHeight;
- leftedge=gui->BorderLeft;
- gui->InnerHeight+=8+14;
-
- newgad.ng_TextAttr = &GUI_TopazFont;
- newgad.ng_VisualInfo = gui->VisualInfo;
- newgad.ng_LeftEdge = leftedge+textwidth;
- newgad.ng_TopEdge = topedge;
- newgad.ng_Width = 14;
- newgad.ng_Height = 14;
- newgad.ng_GadgetText = "Click to Front";
- newgad.ng_GadgetID = ClickToFront_ID;
- newgad.ng_Flags = 0;
-
- glist = CreateGadget(CHECKBOX_KIND, glist, &newgad,
- GTCB_Checked,ctf,
- GA_RelVerify,TRUE,
- TAG_DONE);
- if(!glist)
- return(NULL);
-
- topedge=gui->BorderTop+gui->InnerHeight;
- gui->InnerHeight+=8+14;
-
- newgad.ng_TextAttr = &GUI_TopazFont;
- newgad.ng_VisualInfo = gui->VisualInfo;
- newgad.ng_LeftEdge = leftedge+textwidth;
- newgad.ng_TopEdge = topedge;
- newgad.ng_Width = 14;
- newgad.ng_Height = 14;
- newgad.ng_GadgetText = "MMB Shift";
- newgad.ng_GadgetID = MMBShift_ID;
- newgad.ng_Flags = 0;
-
- glist = CreateGadget(CHECKBOX_KIND, glist, &newgad,
- GTCB_Checked,mmb,
- GA_RelVerify,TRUE,
- TAG_DONE);
-
- return(glist);
- }
-
-
- struct Gadget *BuildSliders(struct GUIContext *gui,struct Gadget *glist)
- {
- struct NewGadget newgad;
- int topedge,leftedge,textwidth,textwidth2,level,id=0;
-
- if(Cx)
- level=Cx->MouseSpeed;
- else
- level=(GetNumericToolType("MouseSpeed",100));
-
- textwidth=TextLength(&gui->Screen->RastPort,"Speed: 300%",11);
-
- /* The offsets of our window borders */
- gui->BorderLeft = gui->Screen->WBorLeft;
- gui->BorderTop = gui->Screen->WBorTop + (gui->Screen->Font->ta_YSize + 1);
-
- topedge=8+gui->BorderTop;
- leftedge=16;
- gui->InnerHeight+=30;
- gui->InnerWidth=28;
- textwidth+=20;
-
- /* Setup our first gadget */
- newgad.ng_TextAttr = &GUI_TopazFont;
- newgad.ng_VisualInfo = gui->VisualInfo;
- newgad.ng_LeftEdge = leftedge+textwidth;
- newgad.ng_TopEdge = topedge;
- newgad.ng_Width = 140;
- newgad.ng_Height = 16;
- newgad.ng_GadgetText = NULL;
- newgad.ng_GadgetID = 1;
- newgad.ng_Flags = PLACETEXT_LEFT;
- /* Now create it and add it to our list */
- glist = CreateGadget(SLIDER_KIND, glist, &newgad,
- GA_RelVerify,TRUE,
- GTSL_LevelFormat,"Speed: %ld%%",
- GTSL_MaxLevelLen,12,
- GTSL_Min,30,
- GTSL_Max,300,
- GTSL_Level,level,
- PGA_Freedom,LORIENT_HORIZ,
- TAG_DONE);
- if(!glist)
- return(NULL);
-
- gui->InnerWidth+=textwidth+140;
- leftedge+=textwidth;
- return(glist);
- }
-
-
- void DisposeGUI(struct GUIContext *gui)
- {
- if(gui->Window)
- gui->Hide(gui);
-
- FreeVec(gui);
- }
-
-
- char *Window_Open(struct GUIContext *gui)
- {
- struct Gadget *glist = NULL;
-
- if(gui->Window)
- return("Window already open!");
-
- gui->InnerWidth=0;
- gui->InnerHeight=0;
-
- if(!(gui->Screen=LockPubScreen(NULL)))
- return(NULL);
-
- if(!(gui->VisualInfo = GetVisualInfo(gui->Screen, TAG_DONE)))
- return(NULL);
-
- if(!(gui->ContextGadget = CreateContext(&glist)))
- return(NULL);
-
- if(!(glist=BuildSliders(gui,glist)))
- return(NULL);
-
- if(!(glist=BuildCheckBoxes(gui,glist)))
- return(NULL);
-
- if(!(glist=BuildQuitButton(gui,glist)))
- return(NULL);
-
- if(gui->Window = OpenWindowTags(NULL,
- WA_Activate,TRUE,
- WA_InnerWidth,gui->InnerWidth,
- WA_InnerHeight,gui->InnerHeight,
- WA_Flags,WFLG_CLOSEGADGET | WFLG_DEPTHGADGET | WFLG_DRAGBAR,
- WA_IDCMP,SLIDERIDCMP | IDCMP_GADGETUP | IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
- WA_Gadgets,gui->ContextGadget,
- WA_Title,"FreeMouse V1.0",
- TAG_DONE,0))
- {
- GT_RefreshWindow(gui->Window, NULL);
- gui->Signals|=(1<<gui->Window->UserPort->mp_SigBit);
- return(NULL);
- }
- else
- return("Error: could not open window\n");
- }
-
-
- void Window_Close(struct GUIContext *gui)
- {
- if(gui->Window)
- {
- gui->Signals^=(1<<gui->Window->UserPort->mp_SigBit);
- CloseWindow(gui->Window);
- gui->Window=NULL;
- }
-
- if(gui->ContextGadget)
- {
- FreeGadgets(gui->ContextGadget);
- gui->ContextGadget=NULL;
- }
-
- if(gui->VisualInfo)
- {
- FreeVisualInfo(gui->VisualInfo);
- gui->VisualInfo=NULL;
- }
-
- if(gui->Screen)
- {
- UnlockPubScreen(NULL, gui->Screen);
- gui->Screen=NULL;
- }
- }
-
-
- BOOL HandleIDCMP(struct GUIContext *gui,unsigned long signals)
- {
- struct Window *win=gui->Window;
- BOOL cont=TRUE,hide=FALSE;
- long level;
- struct Gadget *gadget;
- if(signals&gui->Signals)
- {
- if(win)
- {
- struct IntuiMessage* intuimsg;
- while(intuimsg = GT_GetIMsg(win->UserPort))
- {
- switch(intuimsg->Class)
- {
- case IDCMP_MOUSEMOVE:
- case IDCMP_GADGETUP:
- if(gadget=(struct Gadget *)intuimsg->IAddress)
- {
- switch(gadget->GadgetID)
- {
- case Speed_ID:
- GT_GetGadgetAttrs(gadget,win,NULL,GTSL_Level,&level,TAG_DONE);
- Cx->MouseSpeed=level;
- break;
- case ClickToFront_ID:
- GT_GetGadgetAttrs(gadget,win,NULL,GTCB_Checked,&level,TAG_DONE);
- Cx->ClickToFront=level;
- break;
- case MMBShift_ID:
- GT_GetGadgetAttrs(gadget,win,NULL,GTCB_Checked,&level,TAG_DONE);
- Cx->MMBShift=level;
- break;
- case Quit_ID:
- cont=FALSE;
- break;
- }
- }
- break;
- case IDCMP_CLOSEWINDOW:
- hide=TRUE;
- break;
- case IDCMP_REFRESHWINDOW:
- GT_BeginRefresh(win);
- GT_EndRefresh(win, TRUE);
- break;
- }
- GT_ReplyIMsg(intuimsg);
- }
- if(hide)
- gui->Hide(gui);
- return(cont);
- }
- }
- return(TRUE);
- }
-
-
- struct GUIContext *CreateGUI()
- {
- struct GUIContext *gui;
-
- if(!(gui=AllocVec(sizeof(struct GUIContext),MEMF_CLEAR)))
- return(NULL);
-
- gui->Dispose=DisposeGUI;
- gui->Show=Window_Open;
- gui->Hide=Window_Close;
- gui->Handle=HandleIDCMP;
-
- return(gui);
- }
-
-